//
//  LoginViewController.m
//  Coding_My
//
//  Created by showXxie on 2017/8/18.
//  Copyright © 2017年 sooxie. All rights reserved.
//

#import "LoginViewController.h"
#import "User.h"

@interface LoginViewController ()

@property (nonatomic,strong) UITextField *userName;

@property (nonatomic,strong) UITextField *password;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _userName = [[UITextField alloc]init];
    [self.view addSubview:_userName];
    _userName.backgroundColor = [UIColor whiteColor];
    
    _password = [[UITextField alloc]init];
    _password.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:_password];
    
    
    [_userName mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view).offset(100);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.height.mas_equalTo(44);
        
    }];
    
    [_password mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.userName.mas_bottom).offset(20);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.height.mas_equalTo(44);

    }];
    
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self.view addSubview:loginBtn];
    loginBtn.backgroundColor = kColorBrandGreen;
    
    [loginBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.password.mas_bottom).offset(20);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.height.mas_equalTo(44);
        
    }];
    
    
      
}


- (void)loginAction {
    
//    NSMutableDictionary *params = @{@"account": self.userName.text,
//                                    @"password" : [self.password.text sha1Str],
//                                    @"remember_me" :  @"true"}.mutableCopy;
    
    NSMutableDictionary *params = @{@"account": @"sooxie",
                                    @"password" : [@"38433859xie" sha1Str],
                                    @"remember_me" :  @"true"}.mutableCopy;
    
    [[NetAPIManager manager] loginPath:@"api/v2/account/login" Params:params andBlock:^(id data, NSError *error) {
        
        User *user = [User mj_objectWithKeyValues:data];
        
    
        
        [((AppDelegate *)[UIApplication sharedApplication].delegate) setupTabViewController];


        
        
        
        
    }];
    
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismissViewControllerAnimated:YES completion:nil];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
